<template>
  <div>
    <el-card>
      <div class="border">
        <span style="font-size: 17px;font-weight: bold">文档回收站</span>
      </div>
      <div class="border1">
        <el-form :inline="true">
          <el-form-item label="标题：">
            <el-input
              class="mr5"
              v-model="formInfo.keywords"
              placeholder="请输入标题"
            ></el-input>
          </el-form-item>
          <el-form-item label="文档类型:">
            <el-select
              class="mr5"
              v-model="formInfo.categoryId"
              placeholder="请选择"
            >
              <el-option
                v-for="item in categoryList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年份：">
            <el-date-picker
              v-model="formInfo.year"
              type="year"
              placeholder="选择年"
              value-format="yyyy"
              :clearable="false"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="search"
              >搜索
            </el-button>
            <el-button icon="el-icon-s-open" type="primary" @click="clear"
              >重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-row style="text-align: center;padding:20px">
        <page-table
          :page-data="DocumentPageList"
          stripe
          border
          :loading="loading"
          style="width: 100%;"
          :do-get-page-data="getMyRelease"
        >
          <el-table-column
            width="100"
            align="center"
            type="index"
            label="序号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="title"
            label="标题"
            width="500"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <a class="task_title_a" @click="examine(scope.row)">{{
                scope.row.title
              }}</a>
            </template>
          </el-table-column>
          <el-table-column
            prop="fileCount"
            align="center"
            label="文档数量"
          ></el-table-column>
          <el-table-column
            prop="categoryName"
            align="center"
            label="文档类型"
          ></el-table-column>
          <el-table-column
            align="center"
            label="发送人"
            prop="createUserName"
          ></el-table-column>
          <el-table-column
            align="center"
            label="发送部门"
            show-overflow-tooltip
            prop="organizeName"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            align="center"
            width="200"
            label="发送时间"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column width="200" align="center" label="管理">
            <template slot-scope="scope">
              <el-tooltip content="查看" placement="top">
                <el-button
                  size="mini"
                  icon="el-icon-view"
                  @click="examine(scope.row)"
                ></el-button>
              </el-tooltip>
              <el-tooltip content="永久删除" placement="top">
                <el-button
                  size="mini"
                  icon="el-icon-delete"
                  @click="delete2(scope.row)"
                ></el-button>
              </el-tooltip>
              <el-tooltip content="恢复" placement="top">
                <el-button
                  size="mini"
                  icon="el-icon-refresh-left"
                  @click="restore(scope.row)"
                >
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </page-table>
      </el-row>
    </el-card>
  </div>
</template>
<script>
export default {
  created() {
    this.getCategoryTree();
    this.getMyRelease();
  },
  data() {
    return {
      loading: false,
      value4: [],
      formInfo: {
        pageIndex: 1,
        pageSize: 10,
        categoryId: "",
        keywords: "",
        deleteFlag: 1,
        module: "DOCUMENT",
        year: String(new Date().getFullYear())
      },
      categoryList: [],
      DocumentPageList: { records: [] }
    };
  },
  methods: {
    //查看
    examine(row) {
      this.$router.push({ name: "examine", query: { row: row.id } });
    },
    //删除
    delete2(row) {
      this.$confirm("确认永久删除当前文档?删除后不可恢复", "提示", {})
        .then(() => {
          let tem = {
            id: row.id
          };
          this.API.deleteDocumentById(tem).then(ret => {
            this.success("删除成功");
            this.getMyRelease();
          });
        })
        .catch(() => {});
    },
    //恢复
    restore(row) {
      this.$confirm("确认从回收站恢复当前文档？", "提示", {})
        .then(() => {
          let tem = {
            id: row.id
          };
          this.API.recoverDocumentById(tem).then(ret => {
            this.success("恢复成功");
            this.getMyRelease();
          });
        })
        .catch(() => {});
    },
    //获取分页
    getMyRelease(val) {
      let tem = Object.assign(this.formInfo, val);
      this.API.getDocumentPageList(tem).then(ret => {
        this.DocumentPageList = ret.data;
        console.log("deleteFlagPageData", this.DocumentPageList);
      });
    },
    //获取文档类型
    getCategoryTree() {
      this.API.getCategoryTree({ type: "DOCUMENT" }).then(res => {
        this.categoryList = res.data;
        console.log("categoryList", this.categoryList);
      });
    },
    //搜索
    search() {
      this.getMyRelease(1);
    },
    //重置
    clear() {
      this.formInfo = {
        pageIndex: 1,
        pageSize: 10,
        keywords: "",
        categoryId: "",
        deleteFlag: 1,
        module: "DOCUMENT",
        year: String(new Date().getFullYear())
      };
      this.value4 = [];
      this.getMyRelease(1);
    }
  }
};
</script>
<style scoped>
/deep/ .el-card__body {
  padding: 0;
}

.border {
  padding: 19px 0 19px 20px;
  border-bottom: 1px solid rgba(224, 238, 249, 1);
}

.border1 {
  padding: 19px 0 0px 20px;
  border-bottom: 1px solid rgba(224, 238, 249, 1);
}
</style>
